package com.hairline.controller;

import com.hairline.bean.Address;
import com.hairline.bean.vo.BaseRespVo;
import com.hairline.bean.vo.WxAddressDetailVO;
import com.hairline.bean.vo.WxAddressRegionVO;
import com.hairline.bean.vo.WxAddressVO;
import com.hairline.service.WxAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("wx")
public class WxAddressController {
    @Autowired
    WxAddressService wxAddressService;

    @GetMapping("address/list")
    public BaseRespVo addressList() {
        int userId = 1;
        List<WxAddressVO> addressList = wxAddressService.addressList(userId);
        return BaseRespVo.ok(addressList);
    }

    @GetMapping("address/detail")
    public BaseRespVo addressDetail(Integer id) {
        System.out.println(id);
        WxAddressDetailVO detail = wxAddressService.addressDetail(id);
        return BaseRespVo.ok(detail);
    }

    @GetMapping("region/list")
    public BaseRespVo regionList(Integer pid) {
        List<WxAddressRegionVO> result = wxAddressService.regionList(pid);
        return BaseRespVo.ok(result);
    }

    @PostMapping("address/save")
    public BaseRespVo addressSave(@RequestBody Address address) {
        Integer userId = 1;
        address.setUserId(userId);
        int addressId = wxAddressService.addressSave(address);
        return BaseRespVo.ok(addressId);
    }

    @PostMapping("address/delete")
    public BaseRespVo addressDelete(@RequestBody Map map) {
        Integer id = (Integer) map.get("id");
        int userId = 1;
        wxAddressService.addressDelete(id);
        return BaseRespVo.ok();
    }
}
